package com.gxy.learn.verify.web;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Description(参数验证)
 * author: Gao xueyong
 * Create at: 2020/4/12 12:20 下午
 */
@Slf4j
@RestController
@RequestMapping("/pathVariable")
public class PathVariableController {

    @RequestMapping(value = {"/checkStr/{code}/{name}", "/checkStr/{name}"}, method = RequestMethod.GET)
    public String pathVariableStrGet(@PathVariable(value = "code", required = false) String code,
                                     @PathVariable(value = "name") String name) {
        //自己主动获取 并根据需求处理
        log.info("code = {}", code);
        log.info("name = {}", name);
        return code + "-" + name;
    }

    @RequestMapping(value = {"/checkStr/{code}/{name}", "/checkStr/{name}"}, method = RequestMethod.POST)
    public String pathVariableStrPost(@PathVariable(value = "code", required = false) String code,
                                      @PathVariable(value = "name") String name) throws Exception {
        //自己主动获取 并根据需求处理
        log.info("code = {}", code);
        log.info("name = {}", name);
        return code + "-" + name;
    }

    @RequestMapping(value = {"/checkStrList/{list}"}, method = RequestMethod.GET)
    public String pathVariableListGet(@PathVariable(value = "list") List<String> list) throws Exception {
        //自己主动获取 并根据需求处理
        log.info("list = {}", list);
        return JSONObject.toJSONString(list);
    }

    @RequestMapping(value = {"/checkStrList/{list}"}, method = RequestMethod.POST)
    public String pathVariableListPost(@PathVariable(value = "list") List<String> list) throws Exception {
        //自己主动获取 并根据需求处理
        log.info("list = {}", list);
        return JSONObject.toJSONString(list);
    }
}
